<?php
class Controller_Experts extends Controller_List {
	
	protected $_expertInfo;
	
	protected function _setIndexCondition(&$conditions,&$message){
		
		$search = _gp("search","array");
		if(!empty($search['domain'])) {
			$domain  = ',' . intval($search['domain']). ',';
		}
	
		$like = array(
			"domain" => $domain,
			"name" => $search['name'],
			"company" => $search['company'],
			"position" => $search['position'],
			"title" => $search['title'],
		);

		$exact = array(
			"type" =>  	 $search['type'],
		);

		$this->assign("search",$search);

		$conditions = $this->phaseConditions($like,$exact,$date,$range);

		!empty($conditions) && $message = "搜索结果:";
	}
	function actionIndex(){
		$search = _gp("search","array");
		$sitenav[M('Experts')->hashType[$search['type']]] = '';
		$this->assign('sitenav',$sitenav);
		C('PAGESIZE',18);		//设置每页显示18个专家
		parent::actionIndex();
	}
	
	function actionDomain(){
		
		$search = _gp("search","array");
		$domain = intval($search['domain']);
		$domainPath = M('ExpertsDomain')->getParents($domain, true, true, $format = "hash");
		array_shift($domainPath); // shift the root id
		foreach ($domainPath as $k => $v){
			$sitenav[$v] = '';
		}
		$this->assign('sitenav',$sitenav);
		$_GET['search']['type'] = "2 3 4";
		C('PAGESIZE',31);		//设置每页显示31个专家
		
		
		//如果没有指定排序是正向还是逆向，则在这里指定默认方向
		if(!_gp('dir','string')){
			if(_gp('order','string') == 'credit'){
				$_GET['dir'] = 'desc';
			}
			if(_gp('order','string') == 'name'){
				$_GET['dir'] = 'asc';
			}
		}
		
		
		parent::actionIndex();		
	}
	
	function actionSearch(){
		
		$sitenav = array('专家搜索'=>null);
		$this->assign('sitenav',$sitenav);
		
		//如果没有指定排序是正向还是逆向，则在这里指定默认方向
		if(!_gp('dir','string')){
			if(_gp('order','string') == 'credit'){
				$_GET['dir'] = 'desc';
			}
			if(_gp('order','string') == 'name'){
				$_GET['dir'] = 'asc';
			}
		}
		
		if(!empty($_GET['stype'])){
			
			$_GET['search'][_gp('stype','string')] = _gp('keywords','string');
		}
		
		C('PAGESIZE',31);		//设置每页显示31个专家
		parent::actionIndex();		
	}
	function actionDynamic(){
		$this->assignExpertInfo();
		$this->display();
	}
	
	function actionDynamicView(){
		$id = _gp('id','int');
		$data = M('ExpertsDynamic')->be($id);
		$this->assign('d_data',$data);
		$_GET['uid'] = $data['uid'];
		$this->assignExpertInfo();
		$this->display();
	}
	
	function actionView(){
		$this->assignExpertInfo();
		$this->assign("e_title","个人简历");
		$this->assign("e_detail",$this->_expertInfo['detail']);
		$this->display();
	}
	
	function actionPaperList(){
		$this->assignExpertInfo();
		$user = addslashes($this->_expertInfo['name']);
		$papers = M("Papers")->findByAuthor($user);
		
		$this->assign("papers",$papers);
		$this->display();
	}
	
	function actionNewsList(){
		$this->assignExpertInfo();
		$user = addslashes($this->_expertInfo['name']);
		$data = M("News")->findRelevantNewsByExpert($user);
		$this->assign("news",$data);
		$this->display();
	}
	
	function actionPhotos(){
		$this->assignExpertInfo();
		$this->assign("e_title","个人相册");
		$this->assign("e_detail",$this->_expertInfo['pictures']);
		$this->display("Experts_View");
	}
	
	function actionWorks(){
		$this->assignExpertInfo();
		$this->assign("e_title","主要著作");
		$this->assign("e_detail",$this->_expertInfo['works']);
		$this->display("Experts_View");
	}
	
	function actionStudents(){
		$this->assignExpertInfo();
		$this->assign("e_title","弟子心声");
		$this->assign("e_detail",$this->_expertInfo['student']);
		$this->display("Experts_View");
	}
	
	function assignExpertInfo(){
		$uid = _gp("uid",'int');
		$data = $this->selectRow("*","where uid='$uid'");
		if(empty($data)){
			_message("该专家不存在");
		}
		$this->_expertInfo = $data;
		
		$this->assign("data", $data);
		$this->assign("uid", $uid);
	}
			
	function actionPerson(){
		$this->display();
	}
	
	function actionBoard(){
		$this->display();
	}

}